<!DOCTYPE html>
<html lang='en'>

<head>
    <meta charset='UTF-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Document</title>
    <script src='../node_modules/react/umd/react.development.js'></script>
    <script src='../node_modules/react-dom/umd/react-dom.development.js'></script>
    <script src='../node_modules/babel-standalone/babel.min.js'></script>
    <script src='../node_modules/prop-types/prop-types.js'></script>
</head>

<body>
    <div id='root'></div>
    <script type='text/babel'>
        class Son extends React.Component {
            render() {
                return (
                    <div style={{ display: this.props.showName ? "block" : "none" }}>劳资是Son</div>
                )
            }

            componentWillUnmount() {
                console.log("componentWillUnmount");
            }
        }

        class Daddy extends React.Component {
            constructor(props) {
                super(props)
                this.state = {
                    sonShowDiv: true,
                    showSon: true
                }
            }
            
            render() {
                return (
                    <div>
                        {this.state.showSon && <Son showName={this.state.sonShowDiv} />}
                        <button onClick={
                            () => {
                                this.setState({
                                    showSon: !this.state.showSon
                                })
                            }
                        }>显示/隐藏子组件</button>
                    </div>
                )
            }
        }
        
        ReactDOM.render(<Daddy />, document.getElementById('root'))
    </script>
</body>

</html>